set(COMPILER "gcc")
set(USBIP "ch32")
set(CHIP_FAMILY "ch32v30x")
set(TOOLCHAIN_PREFIX riscv-none-embed-)

if(${DEMO_TYPE} STREQUAL "device")
    if(${PORT_SPEED} STREQUAL "fs")
        set(USB_DRV "usb_dc_usbfs.c")
    elseif(${PORT_SPEED} STREQUAL "hs")
        sdk_add_compile_definitions(-DCONFIG_USB_HS)
        set(USB_DRV "usb_dc_usbhs.c")
    endif()
    sdk_append_source($ENV{WCHEVT_SDK_BASE}/board/startup/startup_ch32v30x_D8C.S)
    sdk_set_linker_script($ENV{WCHEVT_SDK_BASE}/board/linker/ch32v30x.ld)
    sdk_add_compile_definitions(-DCONFIG_USBDEV_ALIGN_CHECK_DISABLE)
    # message(STATUS "${Red}Please remove const before descriptor${ColourReset}")
elseif(${DEMO_TYPE} STREQUAL "host")
    if(${PORT_SPEED} STREQUAL "fs")
        set(USB_DRV "usb_hc_usbfs.c")
    elseif(${PORT_SPEED} STREQUAL "hs")
        set(USB_DRV "usb_hc_usbhs.c")
    endif()
    sdk_append_source($ENV{WCHEVT_SDK_BASE}/board/startup/startup_ch32v30x_rtt.S)
    sdk_set_linker_script($ENV{WCHEVT_SDK_BASE}/board/linker/ch32v307_rtt.ld)
    sdk_add_compile_definitions(-DCH32V307)
    sdk_add_compile_definitions(-DCONFIG_USBHOST_PIPE_NUM=16)
    if(${PORT_SPEED} STREQUAL "fs")
        sdk_add_compile_definitions(-DUSBH_IRQHandler=OTG_FS_IRQHandler)
    elseif(${PORT_SPEED} STREQUAL "hs")
        sdk_add_compile_definitions(-DUSBH_IRQHandler=USBHS_IRQHandler)
    endif()
endif()

sdk_add_compile_options(-march=rv32imacxw -mabi=ilp32 -mcmodel=medany -msmall-data-limit=8 -mno-save-restore)
sdk_add_compile_options(-fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Os -Wall)

sdk_append_source($ENV{WCHEVT_SDK_BASE}/board/startup/ch32v30x.c)

sdk_add_link_options(-nostartfiles -Xlinker --gc-sections -Wl,--print-memory-usage --specs=nano.specs --specs=nosys.specs)

